package com.siau.SevenBubble

import hhm.android.library.utils.DataStoreUtils
import hhm.android.library.utils.GetStringListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.first
import siau.android.base.GetBooleanListener

class SplashActivityKotlinHelper : CoroutineScope by MainScope() {
    fun readBooleanFromDataStore(key: String, listener: GetBooleanListener) {
        async {
            val notFirst = DataStoreUtils.readBooleanFromDataStore(key).first()
            listener.getBoolean(notFirst)
        }
    }

    fun writeBooleanToDataStore(key: String, value: Boolean) {
        async {
            DataStoreUtils.writeBooleanToDataStore(key, value)
        }
    }

    fun readStringFromDataStore(key: String, listener: GetStringListener) {
        async {
            val token: String = DataStoreUtils.readStringFromDataStore(key).first()
            listener.getString(token)
        }
    }

    fun writeStringToDataStore(key: String, value: String) {
        async {
            DataStoreUtils.writeStringToDataStore(key, value)
        }
    }

}